#include <iostream>
#include <vector>
using namespace std;

void printMatrix(int n, vector<vector<int>>& matrix) {
    int top = 0, bottom = n - 1, left = 0, right = n - 1;
    while (top <= bottom && left <= right) {
        for (int i = left; i <= right; ++i) {
            cout << matrix[top][i] << " ";
        }
        ++top;
        for (int i = top; i <= bottom; ++i) {
            cout << matrix[i][right] << " ";
        }
        --right;
        if (top <= bottom) {
            for (int i = right; i >= left; --i) {
                cout << matrix[bottom][i] << " ";
            }
            --bottom;
        }
        if (left <= right) {
            for (int i = bottom; i >= top; --i) {
                cout << matrix[i][left] << " ";
            }
            ++left;
        }
    }
}

int main() {
    int n;
    cout << "请输入一个正整数 n (n<=100)：";
    cin >> n;
    vector<vector<int>> matrix(n, vector<int>(n));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> matrix[i][j];
        }
    }
    printMatrix(n, matrix);
    return 0;
}